package com.power.controller;

import com.power.domain.SysMenu;
import com.power.model.MenuAndAuth;
import com.power.model.Result;
import com.power.service.SysMenuService;
import com.power.util.AuthUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Set;

@RestController
@Api(tags = "系统权限接口管理")
@RequestMapping("sys/menu")
public class SysMenuController {

    @Resource
    private SysMenuService sysMenuService;

    @ApiOperation("查询登录用户的菜单全新和操作权限")
    @GetMapping("nav")
    public Result<MenuAndAuth> loadSysUserMenuAndAuth() {

        //查询用户的菜单权限集合
        Set<SysMenu> menus = sysMenuService.selectSysMenuListByUserId(AuthUtils.getLoginSecurityUserId());
        //查询用户的操作权限的集合,从Security的容器中获取安全用户对象的securityUser
        Set<String> perms = AuthUtils.getLoginSecurityUserPerms();

        //封装的菜单的权限和操作权限
        MenuAndAuth menuAndAuth = new MenuAndAuth(menus,perms);
        return Result.success(menuAndAuth);
    }


}
